//
//  HeaderViewController.m
//  budejiePersonalPage
//
//  Created by 李叶夫 on 16/8/30.
//  Copyright © 2016年 李叶夫. All rights reserved.
//

#import "HeaderViewController.h"
#import <UIImageView+WebCache.h>


@interface HeaderViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *userIcon;

@property (weak, nonatomic) IBOutlet UILabel *userNameLabel;

@property (weak, nonatomic) IBOutlet UILabel *userLevelLabel;

@property (weak, nonatomic) IBOutlet UILabel *userScoreLabel;

@property (weak, nonatomic) IBOutlet UILabel *concernLabel;

@property (weak, nonatomic) IBOutlet UILabel *fansLabel;
//简介
@property (weak, nonatomic) IBOutlet UILabel *userTagLabel;

@property (weak, nonatomic) IBOutlet UILabel *topicCountLabel;

@property (weak, nonatomic) IBOutlet UILabel *shareCountLabel;

@property (weak, nonatomic) IBOutlet UILabel *commentCountLabel;

@property (weak, nonatomic) IBOutlet UIImageView *backgroundImageView;

@property (weak, nonatomic) IBOutlet UIButton *topicBtn;

@property (weak, nonatomic) IBOutlet UIButton *shareBtn;

@property (weak, nonatomic) IBOutlet UIButton *commentBtn;

//按钮下面的红色view
@property (weak, nonatomic) UIView *redView;
@property (weak, nonatomic) IBOutlet UIView *bottomView;

@end

@implementation HeaderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIView *redView = [UIView new];
    [self.bottomView addSubview:redView];
    redView.backgroundColor = [UIColor redColor];
    self.redView = redView;
    
    NSLog(@"%@",NSStringFromCGRect(self.topicBtn.frame));
    redView.frame = CGRectMake(self.topicBtn.frame.origin.x, self.topicBtn.frame.origin.y + self.topicBtn.bounds.size.height, self.topicBtn.bounds.size.width, 2);
    
    
}


- (void)setModel:(HeaderModel *)model
{
    _model = model;
    
    self.userNameLabel.text = model.username;
    
    [self.userIcon sd_setImageWithURL:[NSURL URLWithString:model.profile_image]];
    
    self.userLevelLabel.text = [NSString stringWithFormat:@"等级:LV%@",model.level];
    
    self.userScoreLabel.text = [NSString stringWithFormat:@"积分:%@",model.credit];
    
    self.concernLabel.text = model.follow_count;
    self.fansLabel.text = model.fans_count;
    self.topicCountLabel.text = [NSString stringWithFormat:@"%@",model.tiezi_count];
    self.shareCountLabel.text = model.share_count;
    self.commentCountLabel.text = model.comment_count;
    
    [self.backgroundImageView sd_setImageWithURL:[NSURL URLWithString:model.background_image]];
    CGSize viewSize = self.view.bounds.size;
    CGSize tagSize = self.userTagLabel.bounds.size;
    
    if (model.introduction.length == 0) {
        
        [self.userTagLabel removeFromSuperview];
        self.view.bounds = CGRectMake(0, 0, 0, viewSize.height - tagSize.height);
    }else{
        
        self.userTagLabel.text = model.introduction;
    }
}

- (void)viewWillLayoutSubviews
{
    self.userIcon.layer.cornerRadius = self.userIcon.bounds.size.width / 2;
    
    self.userIcon.clipsToBounds = YES;
    self.userIcon.layer.masksToBounds = YES;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 按钮的点击事件
//点击了帖子
- (IBAction)topicAction:(UIButton *)sender {
    
    [UIView animateWithDuration:0.3 animations:^{
        
        self.redView.frame = CGRectMake(sender.frame.origin.x, sender.frame.origin.y + sender.bounds.size.height, sender.bounds.size.width, 2);
    }];
    
    if ([self.delegate respondsToSelector:@selector(loadNewData:)]) {
    
        [self.delegate loadNewData:sender];
    }
    
}


//点击了分享
- (IBAction)shareAction:(UIButton *)sender {
    [UIView animateWithDuration:0.3 animations:^{
        
        self.redView.frame = CGRectMake(sender.frame.origin.x, sender.frame.origin.y + sender.bounds.size.height, sender.bounds.size.width, 2);
    }];

    
    if ([self.delegate respondsToSelector:@selector(loadNewData:)]) {
        
        [self.delegate loadNewData:sender];
    }

}

//点击了评论
- (IBAction)commentAction:(UIButton *)sender {
    [UIView animateWithDuration:0.3 animations:^{
        
        self.redView.frame = CGRectMake(sender.frame.origin.x, sender.frame.origin.y + sender.bounds.size.height, sender.bounds.size.width, 2);
    }];

    
    if ([self.delegate respondsToSelector:@selector(loadNewData:)]) {
        
        [self.delegate loadNewData:sender];
    }

}




/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
